<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class MaintainInfo extends Model
{
    public $fillable = [
    	'device_code',
    	'customer_name',
    	'phone',
    	'installation_address',
    	'component',
    	'charge',
    	'operator',
        'operator_phone',
    	'maintain_at',
        'reserve_at',
        'status',
        'remark',
    ];

    protected $dates = [
        'maintain_at',
        'reserve_at',
        ];

    public function setReserveAtAttribute($value)
    {
        $this->attributes['reserve_at'] = Carbon::createFromFormat('Y-m-d H', $value);
    }

    public function setMaintainAtAttribute($value)
    {
        if(!empty($value)){
            $this->attributes['maintain_at'] = Carbon::createFromFormat('Y-m-d', $value);
        }
    }
}
